package unit10.replaceParameterWithMethods;

/**
 * @author v_irlwang
 * @date 2021/5/11
 */
public class ExampleAfter {

    //数量
    private int quantity;
    //单价
    private double itemPrice;

    public double getPrice() {
        return discountedPrice();
    }

    private double discountedPrice() {
        if (getDiscountLevel() == 2) {
            return getBasePrice() * 0.1;
        }
        return getBasePrice() * 0.2;
    }

    double getBasePrice() {
        return quantity * itemPrice;
    }

    int getDiscountLevel() {
        if (quantity > 100) {
            return 2;
        }
        return 1;
    }

    public static void main(String[] args) {

        String format = String.format("%.2f", 0.234);
        System.out.println(format);

    }

}
